import re

# 字符
# [\w] == [0-9a-zA-Z\u4e00-\u9fa5]
# 所有字符：[\d\D]
# 中文和字符： [^\x00-\xff]
text = '中文1234，564\n'
res = re.match(r'[\u4e00-\u9fa5]+', text)
print(res.group())  # 中文

# \w， 不包括标点
res_w = re.findall(r'[\w]', text)   # ['中', '文', '1', '2', '3', '4', '5', '6', '4']
# 等效 \w
res_o = re.findall(r'[0-9a-zA-Z\u4e00-\u9fa5]', text) # ['中', '文', '1', '2', '3', '4', '5', '6', '4']
# 所有字符，包括\n等字符和标点
res_a = re.findall(r'[\d\D]', text) # ['中', '文', '1', '2', '3', '4', '，', '5', '6', '4', '\n']
# 字符，非标点
res_s = re.findall(r'[\s]', text)  # ['\n']
# 中文
res_chinese = re.findall(r'[^\x00-\xff]', text)
# 所有字符，但不包括\n等字符，单包括标点
res_point = re.findall(r'.', text) # ['中', '文', '，']
print(res_w)
print(res_o)
print(res_a)
print(res_s)
print(res_chinese)
print(res_point)

text = \
    """
<tr class = "hots">
    <td class = "1">hot1</td>
    <td class = "2">hot2</td>
    <td class = "3">hot3</td>
    <td class = "4">hot4</td>
    <td class = "5">hot5</td>
    <td class = "6">爬虫</td>
</tr>
"""
# 贪婪模式
res = re.match(r'\n<tr[\d\D]+>', text)
print('贪婪模式: {}'.format(res.group()))

# 非贪婪模式
res1 = re.match(r'\n<tr[\d\D]+?>', text)
print('非贪婪模式：{}'.format(res1.group()))

text = '1/(11-2+3) 1/22*3 1/(5+6+7/24)'

res = re.findall(r'\w/[\D]*([\d\+\-\*/]*)', text)
print(res)